package com.cogwheel.framework.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import com.cogwheel.framework.init.CPreferences;

public class CConfiguration {
	public static void CWGReadConfiguration(String fileplace, CPreferences preferences){
		try{
			String cLine = "";
			BufferedReader bReader = new BufferedReader(new FileReader(new File(fileplace)));
			
			while((cLine = bReader.readLine()) != null){
				cLine = cLine.replace(" ", "");
				String[] sLine = cLine.split("=");
				
				if (sLine[0].toUpperCase().equals("WINDOW_WIDTH")){ preferences.WINDOW_SIZE.width = Integer.parseInt(sLine[1]); }
				if (sLine[0].toUpperCase().equals("WINDOW_HEIGHT")){ preferences.WINDOW_SIZE.height = Integer.parseInt(sLine[1]); }
				if (sLine[0].toUpperCase().equals("FULLSCREEN")){ if (sLine[1].equals("0")){ preferences.FULLSCREEN = false; }else{ preferences.FULLSCREEN = true; } }
				if (sLine[0].toUpperCase().equals("HIDE_MOUSE")){ if (sLine[1].equals("0")){ preferences.MOUSEDISABLED = false; }else{ preferences.MOUSEDISABLED = true; } }
				if (sLine[0].toUpperCase().equals("GAME_SPEED")){ preferences.FPS_MAX = Integer.parseInt(sLine[1]); }
				
				CDebug.info("CConfiguration", "Read " + sLine[0].toUpperCase() + " with value " + sLine[1] );
			}
			bReader.close();
		}catch(IOException e){ CDebug.info("CWGConfiguration", "Could not read configuration file: " + fileplace); }
	}
}
